package com.pingtai.manage.action;

import java.util.Date;

import com.pingtai.common.entity.IndexPointOut;
import com.pingtai.indent.entity.UserBaseIndentType;
import com.pingtai.indent.service.WeiboIndentService;
import com.pingtai.manage.service.NoticeService;
import com.pingtai.manage.service.ProduceManageService;
import com.pingtai.user.entity.User;
import com.pingtai.user.service.UserManagerService;
import com.pingtai.util.PaginationSupport;
import com.pingtai.util.Utils;

public class PorduceManageAction {

	private UserManagerService userManagerService;
	private WeiboIndentService weiboIndentService;
	private NoticeService noticeManageService;
	private ProduceManageService produceManageService;
	
	private Integer currentPage;
	private Integer pageNum;
	private PaginationSupport paginationSupport;
	private IndexPointOut indexPointOut;
	private IndexPointOut xlPersionRenzhengAddShengming;
	
	
	public IndexPointOut getXlPersionRenzhengAddShengming() {
		return xlPersionRenzhengAddShengming;
	}
	public void setXlPersionRenzhengAddShengming(
			IndexPointOut xlPersionRenzhengAddShengming) {
		this.xlPersionRenzhengAddShengming = xlPersionRenzhengAddShengming;
	}
	public IndexPointOut getIndexPointOut() {
		return indexPointOut;
	}
	public void setIndexPointOut(IndexPointOut indexPointOut) {
		this.indexPointOut = indexPointOut;
	}
	public ProduceManageService getProduceManageService() {
		return produceManageService;
	}
	public void setProduceManageService(ProduceManageService produceManageService) {
		this.produceManageService = produceManageService;
	}
	public UserManagerService getUserManagerService() {
		return userManagerService;
	}
	public void setUserManagerService(UserManagerService userManagerService) {
		this.userManagerService = userManagerService;
	}
	public WeiboIndentService getWeiboIndentService() {
		return weiboIndentService;
	}
	public void setWeiboIndentService(WeiboIndentService weiboIndentService) {
		this.weiboIndentService = weiboIndentService;
	}
	public NoticeService getNoticeManageService() {
		return noticeManageService;
	}
	public void setNoticeManageService(NoticeService noticeManageService) {
		this.noticeManageService = noticeManageService;
	}
	public Integer getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}
	public Integer getPageNum() {
		return pageNum;
	}
	public void setPageNum(Integer pageNum) {
		this.pageNum = pageNum;
	}
	public PaginationSupport getPaginationSupport() {
		return paginationSupport;
	}
	public void setPaginationSupport(PaginationSupport paginationSupport) {
		this.paginationSupport = paginationSupport;
	}
	
	private Integer base;
	private UserBaseIndentType userBaseIndentType;
	
	
	public UserBaseIndentType getUserBaseIndentType() {
		return userBaseIndentType;
	}
	public void setUserBaseIndentType(UserBaseIndentType userBaseIndentType) {
		this.userBaseIndentType = userBaseIndentType;
	}
	public Integer getBase() {
		return base;
	}
	public void setBase(Integer base) {
		this.base = base;
	}
	public String produceManageUI(){
		if(currentPage>0) {
			pageNum = currentPage;
			currentPage = PaginationSupport.PAGESIZE*(currentPage-1);
		}
		
	    paginationSupport = produceManageService.getBaseIndentTypeForPage(currentPage);
		return "success";
	}
	
	public String toChangeProduce(){
		userBaseIndentType = weiboIndentService.getBaseIndentTypeById(base);
		return "success";
	}
	
	public String changeProduce(){
		UserBaseIndentType baseIndent = weiboIndentService.getBaseIndentTypeById(base);
		Float oldPrice = baseIndent.getPrice();
		if(!oldPrice.equals(userBaseIndentType.getPrice())){
			baseIndent.setUpdateDate(new Date());
		}
		baseIndent.setName(userBaseIndentType.getName());
		baseIndent.setPrice(userBaseIndentType.getPrice());
		baseIndent.setUnit(userBaseIndentType.getUnit());
		baseIndent.setUnit2(userBaseIndentType.getUnit2());
		baseIndent.setEnable(userBaseIndentType.getEnable());
		if(userBaseIndentType.getMinAmount()<=userBaseIndentType.getMaxAmount()){
			baseIndent.setMinAmount(userBaseIndentType.getMinAmount());
			baseIndent.setMaxAmount(userBaseIndentType.getMaxAmount());
		}
		baseIndent.setRemark(userBaseIndentType.getRemark());
		
		produceManageService.updateBaseProduce(baseIndent);
		
		return "success";
		
	}
	
	public String pointOutManageUI(){
		if(currentPage>0) {
			pageNum = currentPage;
			currentPage = PaginationSupport.PAGESIZE*(currentPage-1);
		}
		
		indexPointOut = produceManageService.getIndexPointOut(1);
		xlPersionRenzhengAddShengming = produceManageService.getIndexPointOut(2);
	    paginationSupport = produceManageService.getBaseIndentTypeForPage(currentPage);
		return "success";
	}
	
	public String toChangePointOut(){
		userBaseIndentType = weiboIndentService.getBaseIndentTypeById(base);
		return "success";
	}
	
	public String changePointOut(){
		UserBaseIndentType baseIndent = weiboIndentService.getBaseIndentTypeById(base);
		baseIndent.setPointOut(userBaseIndentType.getPointOut());
		
		produceManageService.updateBaseProduce(baseIndent);
		
		return "success";
	}
	
	public String toChangePointOutForIndex(){
		indexPointOut = produceManageService.getIndexPointOut(base);
		return "success";
	}
	
	public String changePointOutForIndex(){
		IndexPointOut pointOut = produceManageService.getIndexPointOut(base);
		pointOut.setPointOut(indexPointOut.getPointOut());
		produceManageService.updatePointOutForIndex(pointOut);
		return "success";
	}
}
